package com.yan.controller;

import com.dangdang.ddframe.rdb.sharding.id.generator.IdGenerator;
import com.dangdang.ddframe.rdb.sharding.id.generator.self.CommonSelfIdGenerator;
import com.yan.bean.User;
import com.yan.bean.UserSexEnum;
import com.yan.service.User1Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by yanl_ on 2018/5/6.
 */
@Service
@RestController
public class UserController {

  private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private User1Service user1Service;


//    @Autowired
//    private CommonSelfIdGenerator commonSelfIdGenerator;


    @Autowired
    private IdGenerator idGenerator;



    @RequestMapping("/getUsers")
    public List<User> getUsers() {
        List<User> users=user1Service.getUsers();
        return users;
    }

    @RequestMapping(value="/insertUser")
    public String updateTransactional(@RequestParam(value = "userId") int userId,
                                      @RequestParam(value = "orderId") int orderId,
                                      @RequestParam(value = "nickName") String nickName,
                                      @RequestParam(value = "passWord") String passWord,
                                      @RequestParam(value = "userName") String userName ) {
        User  user = new User();
        user.setId(idGenerator.generateId().intValue());
        user.setUserId(userId);
        user.setOrderId(orderId);
        user.setNickName(nickName);
        user.setPassWord(passWord);
        user.setUserName(userName);
        user.setUserSex(UserSexEnum.WOMAN);

        logger.info(user.toString());
        user1Service.inserUser(user);

        return "test";
    }
}